//
//  MLVisitorLoginView.swift
//  Weibo
//
//  Created by 李亮亮 on 16/4/7.
//  Copyright © 2016年 Big Fish. All rights reserved.
//

import UIKit

class MLVisitorLoginView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
        loginBtn.addTarget(self, action: #selector(MLVisitorLoginView.loginBtnDidClick), forControlEvents: .TouchUpInside)
        registerBtn.addTarget(self, action: #selector(MLVisitorLoginView.registerBtnDidClick), forControlEvents: .TouchUpInside)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
    
    // MARK: 按钮点击事件
    @objc private func loginBtnDidClick() {
        print("loginBtnDidClick")
    }
    
    @objc private func registerBtnDidClick() {
        print("registerBtnDidClick")
    }
    
    
    // MARK: - 添加子控件
    func setupUI() {
        
        addSubview(circleIcon)
        addSubview(largeHouse)
        addSubview(tipLabel)
        addSubview(loginBtn)
        addSubview(registerBtn)
        
        // make 就是控件取消了frame布局的对象
        circleIcon.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        largeHouse.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        tipLabel.snp_makeConstraints { (make) in
            make.top.equalTo(circleIcon.snp_bottom).offset(20)
            make.centerX.equalTo(self.snp_centerX)
        }
        loginBtn.snp_makeConstraints { (make) in
            make.width.equalTo(100)
            make.top.equalTo(tipLabel.snp_bottom).offset(20)
            make.centerX.equalTo(self.snp_centerX).offset(-70)
        }
        registerBtn.snp_makeConstraints { (make) in
            make.width.equalTo(100)
            make.top.equalTo(tipLabel.snp_bottom).offset(20)
            make.centerX.equalTo(self.snp_centerX).offset(70)
        }
        
    }
    
    
    // MARK: - 懒加载子控件
    private lazy var circleIcon: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    private lazy var largeHouse: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))

    private lazy var tipLabel: UILabel = {
        let label = UILabel()
        label.text = "关注一些人,回到这里看看有什么惊喜"
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(15)
        label.sizeToFit()
        return label
    }()
    
    private lazy var loginBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("登录", forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(16)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        return btn
    }()
    
    private lazy var registerBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("注册", forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(16)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        return btn
    }()
    
    
    
}
